<?php

namespace App\Admin\Controllers;

use App\Admin\Pages\LiveInfo;
use App\Admin\Repositories\LiveRoom;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use http\Env\Request;

class LiveRoomController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new LiveRoom(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('title');
            $grid->column('anchor');
            $grid->column('room_no');
            $grid->column('room_cover')->image('',80);
            $grid->column('status')->display(function ($released) {
                if ($released == 1){
                    return "<span title='点击进入直播间' class='badge badge-success'><a style='cursor: pointer;' class='act-uIirJxX4WFnA9q5G' href='http://www.hyzf.com/admin/liveRoom?id=$this->id'>直播中</a></span>";
                }else{
                    return '<span class="badge badge-secondary">未直播</span>';
                }
            });
            $grid->column('start_time');
            $grid->column('end_time');
            $grid->actions(function (Grid\Displayers\Actions $actions) {

            });
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new LiveRoom(), function (Form $form) {
            $form->display('id');
            $form->text('title');
            $form->text('anchor');
            $form->text('room_no');
            $form->file('room_cover')->disk('oss')->uniqueName()->autoUpload();
            $form->switch('status');
            $form->datetime('start_time');
            $form->datetime('end_time');
            $form->text('push_url');
            $form->text('pull_url');
            $form->text('playback_url');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }

    public function liveRoom(Content $content,\Illuminate\Http\Request $request)
    {
        $id = $request->get('id');
        return $content->body(new LiveInfo($id));
    }
}
